package com.tianji.learning.service.impl;

import com.tianji.common.utils.BeanUtils;
import com.tianji.common.utils.CollUtils;
import com.tianji.learning.constants.LearningConstants;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.domain.vo.PointsBoardSeasonVO;
import com.tianji.learning.mapper.PointsBoardSeasonMapper;
import com.tianji.learning.service.IPointsBoardSeasonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 林云
 * @since 2023-08-18
 */
@Service
public class PointsBoardSeasonServiceImpl extends ServiceImpl<PointsBoardSeasonMapper, PointsBoardSeason> implements IPointsBoardSeasonService {

    /**
     * 查询所有赛季
     */
    @Override
    public List<PointsBoardSeasonVO> querySeason() {
        //1.查询所有赛季
        List<PointsBoardSeason> seasons = this.list();
        if (CollUtils.isEmpty(seasons)) {
            return CollUtils.emptyList();
        }
        //2.转换成vo
        List<PointsBoardSeasonVO> voList = new ArrayList<>();
        for (PointsBoardSeason season : seasons) {
            PointsBoardSeasonVO vo = BeanUtils.copyBean(season, PointsBoardSeasonVO.class);
            voList.add(vo);
        }
        return voList;
    }

    /**
     * 创建历史赛季排行表
     */
    @Override
    public void createPointsBoardLatestTable(Integer id) {
        getBaseMapper().createPointsBoardLatestTable(LearningConstants.POINT_BOARD_TABLE_PREFIX + id);
    }
}
